namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmUtEditor : FormListEditor
    {
        private IContainer components;
        private LabelControl lblHe_So;
        private LabelControl lblMa_Ut;
        private LabelControl lblTen_Ut;
        private LabelControl lblTen_Ut_E;
        private TextNumeric txtHe_So;
        private TextControl txtMa_Ut;
        private TextControl txtTen_Ut;
        private TextControl txtTen_Ut_E;

        public FormDmUtEditor()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDmUtEditor));
            this.txtMa_Ut = new TextControl();
            this.lblMa_Ut = new LabelControl();
            this.txtTen_Ut = new TextControl();
            this.lblTen_Ut = new LabelControl();
            this.txtTen_Ut_E = new TextControl();
            this.lblTen_Ut_E = new LabelControl();
            this.lblHe_So = new LabelControl();
            this.txtHe_So = new TextNumeric();
            base.SuspendLayout();
            base.txtMa_Loai3.FirstFilter = "Type = 'UT3'";
            base.txtMa_Loai3.Location = new Point(0x18c, 0x74);
            base.txtMa_Loai3.Size = new Size(0x85, 20);
            base.txtMa_Loai3.TabIndex = 6;
            base.txtMa_Loai2.FirstFilter = "Type = 'UT2'";
            base.txtMa_Loai2.Location = new Point(0x103, 0x74);
            base.txtMa_Loai2.Size = new Size(0x86, 20);
            base.txtMa_Loai2.TabIndex = 5;
            base.txtMa_Loai1.FirstFilter = "Type = 'UT1'";
            base.txtMa_Loai1.Location = new Point(0x7b, 0x74);
            base.txtMa_Loai1.Size = new Size(0x85, 20);
            base.txtMa_Loai1.TabIndex = 4;
            base.lblPhan_Loai.Location = new Point(12, 0x77);
            this.txtMa_Ut.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Ut.CheckTextSearched = false;
            this.txtMa_Ut.DisabledForeColor = Color.Empty;
            this.txtMa_Ut.Font = new Font("Arial", 8.25f);
            this.txtMa_Ut.Location = new Point(0x7b, 0x1c);
            this.txtMa_Ut.MaxLength = 0x20;
            this.txtMa_Ut.Name = "txtMa_Ut";
            this.txtMa_Ut.OldValue = null;
            this.txtMa_Ut.Size = new Size(0x85, 20);
            this.txtMa_Ut.TabIndex = 0;
            this.txtMa_Ut.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Ut.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Ut.Value = null;//manager.GetObject("txtMa_Ut.Value");
            this.lblMa_Ut.AutoSize = true;
            this.lblMa_Ut.Font = new Font("Arial", 8.25f);
            this.lblMa_Ut.Location = new Point(12, 0x1f);
            this.lblMa_Ut.Name = "lblMa_Ut";
            this.lblMa_Ut.Size = new Size(0x39, 14);
            this.lblMa_Ut.TabIndex = 4;
            this.lblMa_Ut.Text = "Mã ưu ti\x00ean";
            this.txtTen_Ut.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Ut.CheckTextSearched = false;
            this.txtTen_Ut.DisabledForeColor = Color.Empty;
            this.txtTen_Ut.Font = new Font("Arial", 8.25f);
            this.txtTen_Ut.Location = new Point(0x7b, 50);
            this.txtTen_Ut.MaxLength = 128;
            this.txtTen_Ut.Name = "txtTen_Ut";
            this.txtTen_Ut.OldValue = null;
            this.txtTen_Ut.Size = new Size(0x196, 20);
            this.txtTen_Ut.TabIndex = 1;
            this.txtTen_Ut.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Ut.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Ut.Value = null;//manager.GetObject("txtTen_Ut.Value");
            this.lblTen_Ut.AutoSize = true;
            this.lblTen_Ut.Font = new Font("Arial", 8.25f);
            this.lblTen_Ut.Location = new Point(12, 0x35);
            this.lblTen_Ut.Name = "lblTen_Ut";
            this.lblTen_Ut.Size = new Size(0x3d, 14);
            this.lblTen_Ut.TabIndex = 4;
            this.lblTen_Ut.Text = "Tên ưu ti\x00ean";
            this.txtTen_Ut_E.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Ut_E.CheckTextSearched = false;
            this.txtTen_Ut_E.DisabledForeColor = Color.Empty;
            this.txtTen_Ut_E.Font = new Font("Arial", 8.25f);
            this.txtTen_Ut_E.Location = new Point(0x7b, 0x48);
            this.txtTen_Ut_E.MaxLength = 128;
            this.txtTen_Ut_E.Name = "txtTen_Ut_E";
            this.txtTen_Ut_E.OldValue = null;
            this.txtTen_Ut_E.Size = new Size(0x196, 20);
            this.txtTen_Ut_E.TabIndex = 2;
            this.txtTen_Ut_E.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Ut_E.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Ut_E.Value = null;//manager.GetObject("txtTen_Ut_E.Value");
            this.lblTen_Ut_E.AutoSize = true;
            this.lblTen_Ut_E.Font = new Font("Arial", 8.25f);
            this.lblTen_Ut_E.Location = new Point(12, 0x4b);
            this.lblTen_Ut_E.Name = "lblTen_Ut_E";
            this.lblTen_Ut_E.Size = new Size(0x4a, 14);
            this.lblTen_Ut_E.TabIndex = 4;
            this.lblTen_Ut_E.Text = "Tên tiếng Anh";
            this.lblHe_So.AutoSize = true;
            this.lblHe_So.Font = new Font("Arial", 8.25f);
            this.lblHe_So.Location = new Point(12, 0x61);
            this.lblHe_So.Name = "lblHe_So";
            this.lblHe_So.Size = new Size(0x38, 14);
            this.lblHe_So.TabIndex = 4;
            this.lblHe_So.Text = "Hệ số (%)";
            this.txtHe_So.Font = new Font("Arial", 8.25f);
            this.txtHe_So.Location = new Point(0x7b, 0x5e);
            this.txtHe_So.Name = "txtHe_So";
            int[] bits = new int[4];
            this.txtHe_So.NumericValue = new decimal(bits);
            this.txtHe_So.OldValue = null;
            this.txtHe_So.Size = new Size(0x85, 20);
            this.txtHe_So.TabIndex = 3;
            this.txtHe_So.TextAlign = HorizontalAlignment.Right;
            this.txtHe_So.UserTextNumericFormat = AppInstance.TextNumericFormat.Percent;
//            this.txtHe_So.Value = null;//manager.GetObject("txtHe_So.Value");
            base.AddTitleText = "Thêm mới mức ưu ti\x00ean";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x222, 150);
            base.Controls.Add(this.txtHe_So);
            base.Controls.Add(this.lblHe_So);
            base.Controls.Add(this.lblTen_Ut_E);
            base.Controls.Add(this.lblTen_Ut);
            base.Controls.Add(this.lblMa_Ut);
            base.Controls.Add(this.txtTen_Ut_E);
            base.Controls.Add(this.txtTen_Ut);
            base.Controls.Add(this.txtMa_Ut);
            base.EditTitleText = "Sửa mức ưu ti\x00ean";
            base.FirstFreeCode = "UT1";
            base.Name = "FormDmUtEditor";
            base.SecondFreeCode = "UT2";
            this.Text = "Thêm mới mức ưu ti\x00ean";
            base.ThirdFreeCode = "UT3";
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            base.Controls.SetChildIndex(this.txtMa_Ut, 0);
            base.Controls.SetChildIndex(this.txtTen_Ut, 0);
            base.Controls.SetChildIndex(this.txtTen_Ut_E, 0);
            base.Controls.SetChildIndex(this.lblMa_Ut, 0);
            base.Controls.SetChildIndex(this.lblTen_Ut, 0);
            base.Controls.SetChildIndex(this.lblTen_Ut_E, 0);
            base.Controls.SetChildIndex(this.lblHe_So, 0);
            base.Controls.SetChildIndex(this.txtHe_So, 0);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (string.IsNullOrEmpty(this.txtMa_Ut.Text))
            {
                MessageBox.Show("Chưa nhập mã ưu ti\x00ean!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Ut.Text))
            {
                MessageBox.Show("Chưa nhập tên ưu ti\x00ean!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Ut"] = this.txtMa_Ut.Value;
            localCurrentRow["Ten_Ut"] = this.txtTen_Ut.Value;
            localCurrentRow["Ten_Ut_E"] = this.txtTen_Ut_E.Value;
            localCurrentRow["He_So"] = this.txtHe_So.Value;
            localCurrentRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            DmUtDataAccess access = new DmUtDataAccess();
            if (base.ShowMessage(localCurrentRow, access.SaveRow(base.NewChecked, localCurrentRow)))
            {
                return false;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Ut.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Ut.Value = base.LocalCurrentRow["Ma_Ut"];
            this.txtTen_Ut.Value = base.LocalCurrentRow["Ten_Ut"];
            this.txtTen_Ut_E.Value = base.LocalCurrentRow["Ten_Ut_E"];
            this.txtHe_So.Value = base.LocalCurrentRow["He_So"];
            base.txtMa_Loai1.Value = base.LocalCurrentRow["Ma_Loai1"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.OnShow();
        }
    }
}

